// 系统商品Datatable
var goodsTable;

var skuUpdateTable;

//正在操作的“平台商品ID”
var opGoodsId = "";
var btnAdvSearchflg= false;
var nEditing = null;
var goodsCategoryflg = 0;
var test;
var isSecond = 0;
var chkGoodsArry=new Array();

//初始化iCheck组件
var turn_on_iCheck = function(domElement) {
    return $('input[type="checkbox"],input[type="radio"]', domElement).iCheck({
        checkboxClass : 'icheckbox_flat-red',
        radioClass : 'iradio_flat-red'
    });
};

/**
 * 页面初始化
 */
$(document).ready(function(){  

    // 高级搜索
    $("#advSearchPanel").hide();
    //按钮控制
    setPageElementStatus("goodsList");
    
    //后台交互
    $.ajax({
        type:"POST",
        url:"/goods/isadd.action",
        contentType: "application/json;charset=utf-8",
        dataType: "json",
//        async: false, // 同步
        success:function(data) {
            if (data.success == "y") {
                // if (data.isadd == "y"){
                //     $("#downLoadGoods").hide();
                //     $("#newGoods").show();
                // } else {
                //     $("#downLoadGoods").show();
                //     $("#newGoods").hide();
                // }
            } else{
                window.top.window.showModalAlert(data.errormessage);
            }

        },
        error:function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
    //确认信息画面显示
    var loading = window.top.window.getIndexBusyOverlay();
    $.ajax({
        type: "GET",
        url: "/goods/getGoodsCategory.action",
        contentType: "application/json;charset=utf-8",
        dataType: "json",
//        async: false,//同步
        beforeSend:function(){
            if(loading) {
            	loading.settext("正在处理中，请稍后...");
            }
        },
        success: function (data) {
        	loading.remove();
            if (data.result == "success") {
                //设置商品分类
                  var heads = ["商品分类名称","备注","创建时间","修改时间","操作"];
                  var goodsCategory = data.goodsCategory;
                  if (goodsCategory!==null){
                      $.TreeTable("treeMenu", heads, goodsCategory);
                      test= $("#treeMenu");
                      test.treetable({ expandable: true });
                      // Highlight selected row
                      test.find("tbody").on("mousedown", "tr", function() {
                          window.top.window.$(".selected").removeClass("selected");
                          $(this).toggleClass("selected");
                      });
                      
                      $(".returnGoodsCategory").click(function(){
                          var catgId = $(this).attr("catgId");
                          var catgName = $(this).attr("catgName");
                          if (isSecond==1){
                              $('#catgId').val(catgId);
                              $('#catgName').val(catgName); 
                              $("#catgName").attr("title", catgName);
                              window.top.window.returnCustomModalDialog();
//                              window.top.window.borrowCustomModalDialog($("#modalCreate"));
                              $('#goodsCategorySelect').modal('hide');
                              goodsTable.draw();
                          } else {
                              var params = {};
                              params.catgId = catgId;  
                              params.catgName = catgName;  
                              params.goodsId = chkGoodsArry;
                              
                              $.ajax({
                                  type:"POST",
                                  url:"/goods/updateCategorybyGoodsIds.action",
                                  data:JSON.stringify(params),
                                  contentType: "application/json;charset=utf-8",
                                  dataType: "json",
                                  async: false, // 同步
                                  success:function(data) {
                                      if (data.success == "Y") {
                                          window.top.window.returnCustomModalDialog();
                                          $('#goodsCategorySelect').modal('hide');
                                          goodsTable.draw();
                                      } else{
                                          window.top.window.showModalAlert(data.errormessage);
                                      }
                                      
                                  },
                                  error:function(XMLHttpRequest, textStatus) {
                                      if (XMLHttpRequest.status == 500) {
                                          var result = eval("(" + XMLHttpRequest.responseText + ")");
                                          alert(result.errorObject.errorText);
                                      }
                                  }
                                  });
                          }
                      });
                  }
              } else {
                  window.top.window.showModalAlert(data.msg);
              }
        },
        error: function (XMLHttpRequest, textStatus) {
        	loading.remove();
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
    
 // 快速搜索，点击时提交表格刷新内容
    $("#btnQuickSearch").click(function () {
        goodsTable.draw();
    });

    // 搜索框的回车事件
    $('#quickSearch').keydown(function (e) {
        if (e.keyCode == 13 && $('#btnQuickSearch').is(":visible")) {
            $("#btnQuickSearch").click();
        }
    });
    
    //点击其他地方高级查询收起
    // $("body").click(function(e){
    //     if(btnAdvSearchflg==true){
    //         btnAdvSearchflg = false;
    //     } else {
    //         $("#advSearchPanel").hide();
    //         $("#btnAdvSearch").children("i:eq(0)").removeClass("fa-angle-double-up");
    //         $("#btnAdvSearch").children("i:eq(0)").addClass("fa-angle-double-down");
    //     }
    // });
    // 高级搜索“提交”按钮点击
    $("#advSearchSubmit").click(function (e) {
        //记录高级查询的检索条件
        setHidValue("frmAdvSearch");
        
        goodsTable.draw();
        // $("#advSearchPanel").hide();
        // $("#btnAdvSearch").children("i:eq(0)").removeClass("fa-angle-double-up");
        // $("#btnAdvSearch").children("i:eq(0)").addClass("fa-angle-double-down");
        
    });

    // 高级搜索
    $("#advSearchPanel").hide();
    $("#btnAdvSearch").click(function () {
        btnAdvSearchflg = true;
        if ($("#advSearchPanel").is(":hidden")) {
            $("#advSearchPanel").show();
            $("#btnQuickSearch").hide();
            $(this).children("i:eq(0)").removeClass("fa-angle-double-down");
            $(this).children("i:eq(0)").addClass("fa-angle-double-up");
        } else {
            $("#advSearchPanel").hide();
            $("#btnQuickSearch").show();
            $(this).children("i:eq(0)").removeClass("fa-angle-double-up");
            $(this).children("i:eq(0)").addClass("fa-angle-double-down");
        }
        
    });
    $("#advSearchPanel").click(function () {
        btnAdvSearchflg = true;
    })
    
    
    // 初始化表格控件
    goodsTable = $('#goodsTable').DataTable({
        "processing": true,
        "serverSide": true,
        "lengthMenu": [[10, 25, 50, 100, 500, 1000], [10, 25, 50, 100, 500, 1000]],
        "dom": '<"bottom"rtflp>',
        "searching": false,
        "pagingType": "full_numbers",
        "deferRender": true,
        "scrollX":true,
        // "scrollY":"410px",
        "scrollCollapse":true,
        "ajax": {
            "url": "/goods/goodsList.action",
            "data": function (d) {
                // if ($("#advSearchPanel").is(":hidden")) {

                    d.quickSearch = encodeURI($('#quickSearch').val());

                // }
                // else {

                    // 高级查询条件
                    var goodsName = encodeURI($('#goodsName').val());
                    var goodsCode = encodeURI($('#goodsCode').val());
                    var skuCode = encodeURI($('#skuCode').val());
                    var skuName = encodeURI($('#skuName').val());
                    var barCode = encodeURI($('#barCode').val());
                    var skuMCode = encodeURI($('#skuMCode').val());
                    var advData = {
                        "goodsName": goodsName,
                        "goodsCode": goodsCode,
                        "skuCode": skuCode,
                        "skuName": skuName,
                        "skuMCode":skuMCode,
                        "barCode":barCode
                    };

                    d.formJson = JSON.stringify(advData);
                // }

            }
        },
        "tableTools": {
            "sRowSelect": "bootstrap"
        },
        "columns": [{
            "data": "skuShow"
        },{
            "data": "chk"
        }, {
            "data": "goodsCode"
        }, {
            "data": "goodsName"
        }, {
            "data": "catgName"
        }, {
            "data": "remark"
        }, {
            "data": "isSn",
            "render":function(data){
                if(data=="y"){
                    return "<span class='text-green'>已启用</span>";
                }else{
                    return "<span class='text-muted'>已禁用</span>";
                }
            },
            "className":"text-center"
        }, {
            "data": "operation"
        }
        ],
        "columnDefs": [{
            "orderable": false,
            "targets": [0]
        },{
            "orderable": false,
            "targets": [1]
        }, {
            "orderable": false,
            "targets": [7]
        },{"className": "truncate-text tooltip-column-detail-5", "targets":[3]},
        {"className": "truncate-text tooltip-column-detail-5", "targets":[4]},
        {"className": "truncate-text tooltip-column-detail-5", "targets":[5]},
        ],
        "order": [[2, "asc"], [3, "asc"], [4, "asc"], [5, "asc"]]
    }).on('draw.dt',  function() {
       /*turn_on_iCheck($("#goodsTable_wrapper"));
        $("#chkAll").on("ifChanged", function() {
            if ($("#chkAll").is(":checked")) {
                $("#goodsTable_wrapper").find(".icheck").iCheck("check");
            } else {
                $("#goodsTable_wrapper").find(".icheck").iCheck("uncheck");
            }
        });*/
    });
    
 // 文字过长截断显示悬浮框
    $("#goodsTable").tooltip({
        selector: ".tooltip-column-detail-5,.tooltip-column-detail",
        container: "body",
        title: function() {
            if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                return $(this).text();
            }
        }
    });
    
    $('#goodsTable tbody').on('click', 'td .fa', function () {
        //取得主键
        var goodsId = $(this).attr('goodsId');
        var tr = $(this).closest('tr');
        var row = goodsTable.row(tr);
        if ( row.child.isShown() ) {
            // This row is already open - close it
            row.child.hide();
            tr.removeClass('shown');
            $(this).removeClass('fa-chevron-up');
            $(this).addClass('fa-chevron-down');
        }
        else {
            //关闭其他
            $('#goodsTable tbody tr').each(function(){
                if ($(this).attr("role")=="row"){
                    goodsTable.row($(this)).child.hide();
                }
            });
            $('.fa-chevron-up').addClass('fa-chevron-down');
            $('.fa-chevron-down').removeClass('fa-chevron-up');
            //生成datatable的HTML代码
            //判断相应的id的datatable是否存在
            if ($('#goodsTable' + goodsId).length <= 0) {
                var temp = '';
                temp += '<table id="goodsTable' + goodsId + '"';
                temp += 'class="table table-hover table-striped table-bordered table-advanced tb-sticky-header" style="table-layout:fixed;"';
                temp += 'width="100%">';
                temp += '<thead>';
                temp += '<tr>';
                temp += '<th width="15%" colValue="">主数据编码</th>';
                temp += '<th width="10%" colValue="">规格商家编码</th>';
                temp += '<th width="10%" colValue="">规格名称</th>';
                temp += '<th width="10%" colValue="" style="text-align:right">标准进价</th>';
                temp += '<th width="10%" colValue="" style="text-align:right">标准售价</th>';
                temp += '<th width="10%" colValue="">允许赠品</th>';
                temp += '<th width="10%" colValue="">虚拟商品</th>';
                temp += '<th width="25%" colValue="">条码</th>';
                temp += '</tr>';
                temp += '</thead>';
                temp += '<tbody>';
                temp += '</tbody>';
                temp += '</table>';
                // Open this row
                row.child(temp).show();
                tr.addClass('shown');
                var childTable = new Object();
                childTable.id = "goodsTable" + goodsId;
                childTable.table = $('#goodsTable' + goodsId).DataTable({
                    "bPaginate": false,
                    "processing": true,
                    "serverSide": true,
                    "dom": '<"bottom"rtfli>',
                    "searching": false,
                    "deferRender": true,
                    "info": false,
                    "ajax": {
                        "url": "/goods/showSkuList.action?goodsId="+goodsId
                    },
                    "tableTools": {
                        "sRowSelect": "bootstrap"
                    },
                    "columnDefs" : [ {
                    	"className" : "truncate-text",
                        "targets" : [ 0 ]
                    },{
                    	"className" : "truncate-text",
                        "targets" : [ 1 ]
                    },{
                    	"className" : "truncate-text",
                        "targets" : [ 2 ]
                    },{
                    	"className" : "truncate-text",
                        "targets" : [ 3 ]
                    },{
                    	"className" : "truncate-text",
                        "targets" : [ 4 ]
                    },{
                    	"className" : "truncate-text",
                        "targets" : [ 5 ]
                    },{
                    	"className" : "truncate-text",
                        "targets" : [ 6 ]
                    },{
                    	"className" : "truncate-text",
                        "targets" : [ 7 ]
                    }],
                    "columns": [{
                        "data": "skuMCode"
                    }, {
                        "data": "skuCode"
                    }, {
                        "data": "skuName"
                    }, {
                        "data": "stanPurcPrice",
                        "className":"text-right",
                        "render": numberParser
                    }, {
                        "data": "salePrice" ,
                        "className":"text-right",
                        "render": numberParser
                    }, {
                        "data": "giftsShow"
                    }, {
                        "data": "virtShow"
                    },{
                        "data": "barCode"
                    }
                    ],
                    "columnDefs": [{"className": "truncate-text tooltip-column-detail-5", "targets":[2]}
                    ],
                    "order": [[0, "asc"]]
                });
            } else {
                tr.addClass('shown');
            }
            $(this).addClass('fa-chevron-up');
            $(this).removeClass('fa-chevron-down');
            
            $('#goodsTable' + goodsId).tooltip({
                selector: ".tooltip-column-detail-5,.tooltip-column-detail",
                container: "body",
                title: function() {
                    if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                        return $(this).text();
                    }
                }
            });
        }
    });
    
    //
    $("#btnGoodsCategory").click(function(){
        if (test==null){
            window.top.window.showModalAlert("商品分类没有数据");
        } else {
            window.top.window.returnCustomModalDialog();
            var editDialog = window.top.window.borrowCustomModalDialog($("#goodsCategorySelect"));
            editDialog.modal({show:true, backdrop:'static'});
            isSecond = 1;
        }
    });
    
    $("#btnGoodsCategoryClear").click(function(){
        window.top.window.$('#catgId').val('');
        window.top.window.$('#catgName').val(''); 
    });
    
 // 设置规则详情对话框关闭事件发生
    $('#goodsCategorySelect').on('hide.bs.modal', function () {
        // 父窗体归还本页的编辑对话框
        if (isSecond==1){
            window.top.window.returnCustomModalDialog();
            window.top.window.borrowCustomModalDialog($("#modalCreate"));
        }else {
            window.top.window.returnCustomModalDialog();
        }
    })
    
    $("#expandAll").click(function(){
        test.treetable('expandAll'); return false;
    });
    
    $("#collapseAll").click(function(){
        test.treetable('collapseAll'); return false;
    });
    
    //$("#splitShopForm").on("click",".returnGoodsCategory",function(){
    $(".returnGoodsCategory").click(function(){
        var catgId = $(this).attr("catgId");
        var catgName = $(this).attr("catgName");
        if (isSecond==1){
            $('#catgId').val(catgId);
            $('#catgName').val(catgName); 
            $("#catgName").attr("title", catgName);
            window.top.window.returnCustomModalDialog();
//            window.top.window.borrowCustomModalDialog($("#modalCreate"));
            $('#goodsCategorySelect').modal('hide');
            goodsTable.draw();
        } else {
            var params = {};
            params.catgId = catgId;  
            params.catgName = catgName;  
            params.goodsId = chkGoodsArry;
            
            $.ajax({
                type:"POST",
                url:"/goods/updateCategorybyGoodsIds.action",
                data:JSON.stringify(params),
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                async: false, // 同步
                success:function(data) {
                    if (data.success == "Y") {
                        window.top.window.returnCustomModalDialog();
                        $('#goodsCategorySelect').modal('hide');
                        goodsTable.draw();
                    } else{
                        window.top.window.showModalAlert(data.errormessage);
                    }
                    
                },
                error:function(XMLHttpRequest, textStatus) {
                    if (XMLHttpRequest.status == 500) {
                        var result = eval("(" + XMLHttpRequest.responseText + ")");
                        alert(result.errorObject.errorText);
                    }
                }
                });
            
        }
    });
});


function downLoadGoods(){
    $.ajax({
        type:"POST",
        url:"/goods/downLoadGoods.action?",
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        async: false, // 同步
        success:function(data) {
            if (data.success == "y") {
                goodsTable.draw();
            } else{
                window.top.window.showModalAlert(data.errormessage);
            }

        },
        error:function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
}

/**
 * 打开创建的对话框
 * @returns
 */
function newGoods() {
    $("#goodsCreateForm")[0].reset();
    $("#btnGoodsUpdate").hide();
    $("#btnGoodsAdd").show();
    $("#goodCode").removeAttr("readonly");
    $("#goodName").removeAttr("readonly");
    $("#editTitle").html("新增系统商品");
    creatGoodsDivShow();
    var editDialog = window.top.window.borrowCustomModalDialog($("#modalCreate"));
    editDialog.modal({show:true, backdrop:'static'});
}

function updateGoodsCategory(){
    //判断是否有选中的数据
    chkGoodsArry = new Array();
    $('input:checkbox[name=chkGoods]:checked').each(function(i){
        chkGoodsArry.push($(this).attr("goodsid"));
     });
    
     if(chkGoodsArry.length <= 0){
         window.top.window.showModalAlert("请选择商品");
        return false;
     } 
     
    if (test==null){
        window.top.window.showModalAlert("商品分类没有数据");
    } else {
        window.top.window.returnCustomModalDialog();
        var editDialog = window.top.window.borrowCustomModalDialog($("#goodsCategorySelect"));
        editDialog.modal({show:true, backdrop:'static'});
        isSecond = 0;
    }
}

/**
 * 批量开启序列号管理功能
 * @returns
 */
function updateGoodsIsSnOpen(){
    updateGoodsIsSn("updateGoodsIsSnOpen");
}

/**
 * 批量关闭序列号管理功能
 * @returns
 */
function updateGoodsIsSnClose(){
    updateGoodsIsSn("updateGoodsIsSnClose");
}

function updateGoodsIsSn(operation){
    var params = {};
    var loading = window.top.window.getIndexBusyOverlay();
    params.goodsIds = chkGoodsArry.join(",");
    $.ajax({
        type:"GET",
        url:"/goods/"+operation+".action",
        data:params,
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        beforeSend:function(){
            if(loading) {
            	loading.settext("正在处理中，请稍后...");
            }
        },
//        async: false, // 同步
        success:function(data) {
        	loading.remove();
            if (data.result == "success") {
                // 提示操作成功
                window.top.window.showScoMessage('ok', data.msg);
                goodsTable.draw();
            } else{
                window.top.window.showModalAlert(data.msg);
            }
            
        },
        error:function(XMLHttpRequest, textStatus) {
        	loading.remove();
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                window.top.window.showModalAlert(result.errorObject.errorText);
            }
        }
    });
}

function delGoodsCategory(){
    var params = {};
    params.goodsId = chkGoodsArry;
    params.catgId = "";  
    params.catgName = "";
    $.ajax({
        type:"POST",
        url:"/goods/updateCategorybyGoodsIds.action",
        data:JSON.stringify(params),
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        async: false, // 同步
        success:function(data) {
            if (data.success == "Y") {
                goodsTable.draw();
            } else{
                window.top.window.showModalAlert(data.errormessage);
            }
            
        },
        error:function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
        });
}

function deleteGoodsCategory(){
    //判断是否有选中的数据
    chkGoodsArry = new Array();
    $('input:checkbox[name=chkGoods]:checked').each(function(i){
        chkGoodsArry.push($(this).attr("goodsid"));
     });
    
    if(chkGoodsArry.length <= 0){
        window.top.window.showModalAlert("请选择商品");
       return false;
    } 
    
    window.top.window.showModalConfirm( "是否要清除所选中的系统商品的商品分类？", delGoodsCategory);
    
}

function updateGoodsOpenIsSn(){
    //判断是否有选中的数据
    chkGoodsArry = new Array();
    $('input:checkbox[name=chkGoods]:checked').each(function(i){
        chkGoodsArry.push($(this).attr("goodsid"));
    });
    
    if(chkGoodsArry.length <= 0){
        window.top.window.showModalAlert("请选择商品");
        return false;
    } else if(chkGoodsArry.length>20){
        window.top.window.showModalAlert("由于启用序列号管理操作时间较长，请将批量数限制在20条以内");
        return false;
    }
    
    window.top.window.showModalConfirm( "是否为选中商品启用序列号管理？", updateGoodsIsSnOpen);
}

function updateGoodsCloseIsSn(){
    //判断是否有选中的数据
    chkGoodsArry = new Array();
    $('input:checkbox[name=chkGoods]:checked').each(function(i){
        chkGoodsArry.push($(this).attr("goodsid"));
    });
    
    if(chkGoodsArry.length <= 0){
        window.top.window.showModalAlert("请选择商品");
        return false;
    }
    
    window.top.window.showModalConfirm( "是否为选中商品停用序列号管理？", updateGoodsIsSnClose);
}




$('#modalCreate').on('shown.bs.modal', function () {
    skuCreateTable.fnDraw();
    });

//创建对话框关闭事件发生
$('#modalCreate').on('hide.bs.modal', function () {
    // 父窗体归还本页的编辑对话框
    goodsTable.draw();
    window.top.window.returnCustomModalDialog();
})

// 全选，全不选
var checkboxes = document.getElementsByName('chkGoods');
$("#chkAll").click(function() {
    for (var i = 0; i < checkboxes.length; i++) {
        var checkbox = checkboxes[i];
        if (!$(this).get(0).checked) {
            checkbox.checked = false;
        } else {
            checkbox.checked = true;
        }
    }
});

/**
 * 系统商品的
 * @param btnEdit
 * @returns
 */

/**
 * function showMsg(obj,e)
{
    alert(obj.id);
    stopBubble(e)
}


 */
function operationEdit(btnEdit,e) {
    var goodsid = $(btnEdit).attr("goodsid");
    $("#goodsCreateForm")[0].reset();
    $("#btnGoodsUpdate").show();
    $("#btnGoodsAdd").hide();
    $("#goodCode").attr({ readonly: 'true' });
    $("#goodName").attr({ readonly: 'true' });
    $("#editTitle").html("更新系统商品");
    updateGoodsDivShow(goodsid);
    
    var editDialog = window.top.window.borrowCustomModalDialog($("#modalCreate"));
    editDialog.modal({show:true, backdrop:'static'});

    // 文字过长截断显示悬浮框
//    $('#goodsTable' + goodsid, window.top.document).tooltip({
//        selector : ".tooltip-column-detail",
//        container : "body",
//        title : function() {
//            if ($(this)[0].scrollWidth > $(this).outerWidth()) {
//                return $(this).text();
//            }
//        }
//    });
    
    stopBubble(e);
}
//阻止事件冒泡函数
function stopBubble(e)
{
    if (e && e.stopPropagation)
        e.stopPropagation()
    else
        window.event.cancelBubble=true
}

/**
 * 系统商品删除
 * @param btnDelete
 * @returns
 */
function operationDelete(btnDelete,e) {
	stopBubble(e);
    opGoodsId = $(btnDelete).attr("goodsid");
    window.top.window.showModalConfirm( "删除系统商品将一并删除商品下的所有规格，是否确认删除？", doDelete);
}

//删除
function doDelete() {

  //系统商品信息，其中包括商品，规格集合
    var goodsInfo=new Object();
  //商品信息
    var goods = new Object();
    var loading = window.top.window.getIndexBusyOverlay();
    goods.id = opGoodsId;
    goods.action = "delete";
    goodsInfo.goods = goods;
    goodsInfo.action = "delete"
    $.ajax({
        type:"POST",
        url:"/goods/updateGoods.action",
        data:JSON.stringify(goodsInfo),
        contentType: "application/json;charset=utf-8",
        dataType: "json",
//        async: false, // 同步
        beforeSend:function(){
            if(loading) {
            	loading.settext("正在处理中，请稍后...");
            }
        },
        success:function(data) {
        	loading.remove();
            if (data.success == "y") {
                window.top.window.showScoMessage('ok', '删除成功');
                goodsTable.draw();
            } else{
                window.top.window.showModalAlert(data.errormessage);
            }
            
        },
        error:function(XMLHttpRequest, textStatus) {
        	loading.remove();
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
        });
}

var numberParser = function(data){
    var returnValue = "-";
    var numberData = parseFloat(data);
    if(numberData===+numberData){
        returnValue = numberData.toFixed(2);
    }
    return returnValue;
};

/**
 * 系统商品导出
 */
function exportGoodsList() {
    // 平台规格列名称
    var objSkuMCode = new Object();
    objSkuMCode.name = "主数据编码";
    objSkuMCode.value = "skuMCode";
    var objSkuCode = new Object();
    objSkuCode.name = "规格商家编码";
    objSkuCode.value = "skuCode";
    var objSkuName = new Object();
    objSkuName.name = "规格名称";
    objSkuName.value = "skuName";
    var objSalePrice = new Object();
    objSalePrice.name = "标准售价";
    objSalePrice.value = "salePrice";
    var objGiftsYn = new Object();
    objGiftsYn.name = "允许赠品";
    objGiftsYn.value = "giftsYn";
    var objVirtYn = new Object();
    objVirtYn.name = "虚拟商品";
    objVirtYn.value = "virtYn";
    var objBarCode = new Object();
    objBarCode.name = "条码";
    objBarCode.value = "barCode";

    var obList = [objSkuMCode, objSkuCode, objSkuName, objSalePrice,objGiftsYn,objVirtYn,objBarCode];
    extraFieldJson = JSON.stringify(obList);

    exportList('goodsTable', '/goods/exportCheck.action', '/goods/export.action', 'exportSelectGoods', '系统商品导出', 'frmAdvSearch', extraFieldJson);
}
